package com.agentai.buiness.back.config.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import com.agentai.framework.common.utils.PageResult;
import com.agentai.framework.common.utils.Result;
import com.agentai.buiness.back.config.convert.SysConfigConvert;
import com.agentai.buiness.back.config.entity.SysConfigEntity;
import com.agentai.buiness.back.config.service.SysConfigService;
import com.agentai.buiness.back.config.query.SysConfigQuery;
import com.agentai.buiness.back.config.vo.SysConfigVO;
import org.springdoc.core.annotations.ParameterObject;
// import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;
import java.util.List;

/**
* 系统参数设置表
*
* @since 1.0.0 2024-10-31
*/
@RestController
@RequestMapping("back/buiness/config")
@Tag(name="系统参数设置表")
@AllArgsConstructor
public class SysConfigController {
    private final SysConfigService sysConfigService;

    @GetMapping("page")
    @Operation(summary = "分页")
//    @PreAuthorize("hasAuthority('buiness:config:page')")
    public Result<PageResult<SysConfigVO>> page(@ParameterObject @Valid SysConfigQuery query){
        PageResult<SysConfigVO> page = sysConfigService.page(query);

        return Result.ok(page);
    }

    @GetMapping("{id}")
    @Operation(summary = "信息")
//    @PreAuthorize("hasAuthority('buiness:config:info')")
    public Result<SysConfigVO> get(@PathVariable("id") Long id){
        SysConfigEntity entity = sysConfigService.getById(id);

        return Result.ok(SysConfigConvert.INSTANCE.convert(entity));
    }

    @PostMapping
    @Operation(summary = "保存")
//    @PreAuthorize("hasAuthority('buiness:config:save')")
    public Result<String> save(@RequestBody SysConfigVO vo){
        sysConfigService.save(vo);

        return Result.ok();
    }

    @PutMapping
    @Operation(summary = "修改")
//    @PreAuthorize("hasAuthority('buiness:config:update')")
    public Result<String> update(@RequestBody @Valid SysConfigVO vo){
        sysConfigService.update(vo);

        return Result.ok();
    }

    @DeleteMapping
    @Operation(summary = "删除")
//    @PreAuthorize("hasAuthority('buiness:config:delete')")
    public Result<String> delete(@RequestBody List<Long> idList){
        sysConfigService.delete(idList);

        return Result.ok();
    }
}
